package com.googlecode.lookie.swing.tree.support.file;

import java.io.File;

import javax.swing.Icon;
import javax.swing.filechooser.FileSystemView;
import javax.swing.tree.TreeNode;

import com.googlecode.lookie.swing.tree.render.LabelProvider;

public class FileTreeNodeLabelProvider
    implements LabelProvider
{

    private static final FileSystemView fsv = FileSystemView.getFileSystemView();

    private boolean useNativeIcons;

    public FileTreeNodeLabelProvider()
    {
        this( true );
    }

    public FileTreeNodeLabelProvider( boolean useNativeIcons )
    {
        super();
        this.useNativeIcons = useNativeIcons;
    }

    public boolean isUseNativeIcons()
    {
        return useNativeIcons;
    }

    public void setUseNativeIcons( boolean useNativeIcons )
    {
        this.useNativeIcons = useNativeIcons;
    }

    public Icon getIcon( TreeNode node )
    {
        if ( node instanceof FileTreeNode )
        {
            FileTreeNode n = (FileTreeNode) node;
            File file = n.getFile();
            if ( file != null )
            {
                if ( useNativeIcons )
                {
                    return fsv.getSystemIcon( file );
                }
                else
                {
                    if ( fsv.isComputerNode( file ) )
                    {
                        return getComputerNodeIcon( n );
                    }
                    else
                    {
                        if ( fsv.isDrive( file ) )
                        {
                            return getDriveNodeIcon( n );
                        }
                        else
                        {
                            return getDirectoryNodeIcon( n );
                        }
                    }
                }
            }
        }
        return null;
    }

    public String getText( TreeNode node )
    {
        if ( node instanceof FileTreeNode )
        {
            File file = ( (FileTreeNode) node ).getFile();
            if ( file != null )
            {
                return fsv.getSystemDisplayName( file );
            }
        }
        return null;
    }

    protected Icon getDirectoryNodeIcon( FileTreeNode node )
    {
        return null;
    }

    protected Icon getComputerNodeIcon( FileTreeNode node )
    {
        return null;
    }

    protected Icon getDriveNodeIcon( FileTreeNode node )
    {
        return null;
    }

}
